package com.ccc.scala.base7_collection

import scala.collection.mutable

object Collection12_Map2 {

  def main(args: Array[String]): Unit = {
    // 可变 Map
    val map1 = mutable.Map("a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4)
    val map2 = mutable.Map("e" -> 5, "f" -> 6, "g" -> 7, "h" -> 8)

    // 添加数据
    map1.put("g", 9)
    println(map1) // Map(b -> 2, d -> 4, g -> 9, a -> 1, c -> 3)

    // 修改
    map1.update("g", 111)
    println(map1) // Map(b -> 2, d -> 4, g -> 111, a -> 1, c -> 3)
    map1("g") = 0
    println(map1) // Map(b -> 2, d -> 4, g -> 0, a -> 1, c -> 3)

    // 删除数据
    map1.remove("g")
    println(map1) // Map(b -> 2, d -> 4, a -> 1, c -> 3)

    // 清空
//    map1.clear()
//    println(map1) // Map()

    // 转其他集合

    val set: Set[(String, Int)] = map1.toSet
    val list: List[(String, Int)] = map1.toList
    val seq: Seq[(String, Int)] = map1.toSeq
    val array: Array[(String, Int)] = map1.toArray

    println(map1.keys) // Set(b, d, a, c)
    println(map1.keySet) // Set(b, d, a, c)
    println(map1.keysIterator) // <iterator>
    println(map1.values) // HashMap(2, 4, 1, 3)
    println(map1.valuesIterator) // <iterator>



  }

}
